package com.itheima.service.impl;

import com.itheima.damain.Student;
import com.itheima.dao.imp.StudentDaolmpl;
import com.itheima.service.lnter.IStudentService;

import java.util.ArrayList;

public class StudentServicelmpl implements IStudentService {
    private StudentDaolmpl studentDaolmpl = new StudentDaolmpl();


    // 添加学生
    @Override
    public void addStudent(Student student) {
        studentDaolmpl.addStudent(student);

    }

    // 删除学生
    @Override
    public void deleteStudent(String sid) {
        studentDaolmpl.deleteStudent(sid);
    }

    // 修改学生
    @Override
    public void updateStudent(String sid, Student student) {
        studentDaolmpl.updateStudent(sid, student);
    }

    // 查看学生
    @Override
    public ArrayList<Student> findAllStudent() {
        ArrayList<Student> stu = studentDaolmpl.findAllStudent();
        if (stu != null && stu.size() > 0) {
            return stu;
        }
        return null;
    }

    // 判断学生是否存在
    @Override
    public boolean isExists(String sid) {
        ArrayList<Student> stu = studentDaolmpl.findAllStudent();
        for (int i = 0; i < stu.size(); i++) {
            Student s = stu.get(i);
            if (s != null && s.getSid().equals(sid)) {
                return true;
            }
        }
        return false;
    }
}
